<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<!-- YUI CSS and JavaScript files: -->
<!-- Dependency source file --> 
<script type="text/javascript" src="./js/yahoo-dom-event.js"></script>
<script type="text/javascript" src="./js/yui/connection/connection-min.js"></script>
<script type="text/javascript" src="./js/yui/json/json-min.js"></script>
<script type="text/javascript" src="./js/element-beta-min.js"></script>
<script type="text/javascript" src="./js/yui/paginator/paginator-min.js"></script>
<script type="text/javascript" src="./js/yui/datasource/datasource-min.js"></script>
<script type="text/javascript" src="./js/yui/datatable/datatable-min.js"></script>
<script type="text/javascript" src="./js/yui/container/container-min.js"></script>
<script type="text/javascript" src="./js/yui/button/button-min.js"></script>
<script type="text/javascript" src="./js/yui/event/event-min.js"></script>
<script type="text/javascript" src="./js/yui/calendar/calendar-min.js"></script>
<!-- Required CSS -->
<link type="text/css" rel="stylesheet" href="./js/yui/assets/skins/sam/treeview.css">
<!-- Optional CSS for for date editing with Calendar-->
<link type="text/css" rel="stylesheet" href="./js/yui/assets/skins/sam/calendar.css">
 
<!-- Optional dependency source file --> 
<script src="./js/yui/animation/animation-min.js" type="text/javascript"></script>
 
<!-- TreeView source file --> 
<script src="./js/yui/treeview/treeview-min.js" ></script>
    
<!--begin custom header content for this example-->
<style> 
    #treeDiv1 { background: #fff; padding:1em; margin-top:1em; }
</style>
<!--end custom header content for this example-->
 
<div id="treeDiv1"></div>
    
<script type="text/javascript"> 

YAHOO.util.Event.onDOMReady(function(){
	var tree, currentIconMode;
	
	var generateTree = function() {
        var serviceHeaderId = document.getElementById("serviceHeaderId").value;
        //isdnSendRequest("reserveInfoType_generateReserveInfoJSON.action", '' , "POST", callbackGenerateTree);
        isdnSendRequest("reserveInfoRoom_generateCustomerTreeJSON.action?reserveInfoRoomVO.serviceHeaderId="+serviceHeaderId, '' , "POST", callbackGenerateTree);
    };

    callbackGenerateTree = function() {
        var ready = req.readyState;
        //  console.debug(ready);
        var jsonObject=null;
        if ( ready == 4 ){
            if(req.status == 200) {
                jsonObject=eval( "("+ req.responseText +")" );

                if(jsonObject.object.data){
                    //create a new tree:
                    tree = new YAHOO.widget.TreeView("treeDiv1");
                    
                    //get root node for tree:
                    var root = tree.getRoot(); 

                  	//begin adding children   
                  	var groupName	= document.getElementById("groupName").value;
                  	groupName		= groupName==''?'Group':groupName;
                    var tmpNodeRoot = new YAHOO.widget.MenuNode(groupName, tree.getRoot(), false); 

                    var detail  = jsonObject.object.data['com.appsindy.reserv.vo.CustomerVO'];
                    var size    = 0;
                    var colList;
                    var dataLink;
                    var tmpNode;
                    if(detail){
	                    if(detail.length){
	                        size    = detail.length;
	                        for(var i = 0; i < size; i ++) {
	                        	//dataLink = "<a href='' onclick='gotoReserveDetailByCustomer(" + detail[i].customerId + ")'>" + detail[i].customerName + "</a>";
	                        	dataLink 	= detail[i].customerName;
	                            tmpNode 	= new YAHOO.widget.MenuNode(dataLink, tmpNodeRoot, false);
	                            
	                            genSubTree(tmpNode, detail[i].roomList['com.appsindy.reserv.vo.RoomVO']);                            
	                        }
	                    }else{
	                    	//dataLink = "<a href='' onclick='gotoReserveDetailByCustomer(" + detail.customerId + ")'>" + detail.customerName + "</a>";
	                    	dataLink 	= detail.customerName;
	                        tmpNode 	= new YAHOO.widget.MenuNode(dataLink, tmpNodeRoot, false);
	
	                        genSubTree(tmpNode, detail.roomList['com.appsindy.reserv.vo.RoomVO']);
	                    }
                    }
                    tree.draw();
                }
            }
        }
    };

    function genSubTree(root, detail){
        var dataLink;
        var tmpNode;
        if(detail){
	        if(detail.length){
	            size    = detail.length;
	            for(var i = 0; i < size; i ++) {
	            	//dataLink = "<a href='' onclick='gotoReserveDetailByRoom(" + detail[i].roomId + ")'>" + detail[i].roomCode + "</a>";
	            	dataLink 	= getJSONResult(detail[i].roomCode);
	            	tmpNode 	= new YAHOO.widget.MenuNode(dataLink, root, false);
	            }
	        }else{
	        	//dataLink = "<a href='' onclick='gotoReserveDetailByRoom(" + detail.roomId + ")'>" + detail.roomCode + "</a>";
	        	dataLink 		= getJSONResult(detail.roomCode);
	        	tmpNode 		= new YAHOO.widget.MenuNode(dataLink, root, false);
	        }
        }
    }
    
    //Event.addListener(window, 'load', init);
    generateTree();

});
</script>
 
 
<!--END SOURCE CODE FOR EXAMPLE =============================== -->

